home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Compendium Deluxe 2
/
LSD and 17bit Compendium Deluxe - Volume II.iso
/
a
/
prog
/
misc
/
frefs11.lha
/
FetchRefs
/
Source
/
GenerateIndex
/
GUI.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-19
|
20KB
|
663 lines
/**************************************************************************/
/* GUI.c - all opening and handling of the graphic user interface */
/**************************************************************************/
#include "GenerateIndex.h"
extern struct TagItem MainOutline[], EditOutline[], OptionsOutline[];
extern struct Library *TritonBase;
struct rtFileRequester *DataFileReq, *AddFileReq, *PrefsFileReq;
struct TR_Project *MainPrj, *EditPrj, *OptionsPrj;
struct List EmptyList;
BOOL GoOn = TRUE;
void
OpenEditWindow(void)
{
if (!EditPrj)
{
TR_SetAttribute(MainPrj, MAIN_EDIT_ID, TRAT_Disabled, TRUE);
if (EditPrj = TR_OpenProject(Application, EditOutline))
UpdateMain();
else
TR_SetAttribute(MainPrj, MAIN_EDIT_ID, TRAT_Disabled, FALSE);
}
}
void
LockGUI(void)
{
TR_LockProject(MainPrj);
if (EditPrj)
TR_LockProject(EditPrj);
if (OptionsPrj)
TR_LockProject(OptionsPrj);
}
void
UnlockGUI(void)
{
TR_UnlockProject(MainPrj);
if (EditPrj)
TR_UnlockProject(EditPrj);
if (OptionsPrj)
TR_UnlockProject(OptionsPrj);
}
void
About(void)
{
rtEZRequestTags("GenerateIndex " VERSION " " DATE "\n"
"Index file generator for FetchRefs\n"
"\n"
"By Anders Melchiorsen\n"
"\n"
"FreeWare, 1994",
"Okay",
NULL, NULL,
RTEZ_Flags, EZREQF_CENTERTEXT,
TAG_END, NULL
);
}
ULONG
NumOfNodes(struct List *l)
{
struct Node *n = l->lh_Head;
ULONG cnt = 0;
while (n->ln_Succ)
{
cnt++;
n = n->ln_Succ;
}
return(cnt);
}
struct FileEntry *
SelectedMain(void)
{
struct FileEntry *f;
/* Find pointer to selected node in main listview */
if (IsListEmpty(&FileList))
{
f = NULL;
TR_SetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value, 0);
} else
{
ULONG cnt;
f = (struct FileEntry *)FileList.lh_Head;
cnt = TR_GetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value);
while (cnt--)
f = f->node.ln_Succ;
}
return(f);
}
struct RefsEntry *
SelectedEdit(void)
{
struct FileEntry *f = SelectedMain();
struct RefsEntry *r;
/* Find pointer to selected node in main listview */
if ((f == NULL) || (IsListEmpty(&f->RefsList)))
{
r = NULL;
TR_SetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value, 0);
} else
{
ULONG cnt;
r = (struct RefsEntry *)f->RefsList.lh_Head;
cnt = TR_GetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value);
while (cnt--)
r = r->node.ln_Succ;
}
return(r);
}
void
UpdateMain(void)
{
struct FileEntry *n = SelectedMain();
/* Update main windows 'rescan' and 'delete' gadgets */
TR_SetAttribute(MainPrj, MAIN_RESCAN_ID, TRAT_Disabled, !n);
TR_SetAttribute(MainPrj, MAIN_DELETE_ID, TRAT_Disabled, !n);
/* Update main 'references count' gadget */
TR_SetAttribute(MainPrj, MAIN_REFERENCES_ID, TRAT_Value, n ? NumOfNodes(&n->RefsList) : 0);
/* Update edit 'file' gadget */
if (EditPrj)
TR_SetAttribute(EditPrj, EDIT_FILE_ID, TRAT_Text, (ULONG) (n ? (STRPTR)n->Name : (STRPTR)""));
UpdateEdit();
}
void
UpdateEdit(void)
{
static struct FileEntry *shown;
if (EditPrj)
{
struct RefsEntry *r = SelectedEdit();
/* Update edit windows 'delete' gadget */
TR_SetAttribute(EditPrj, EDIT_DELETE_ID, TRAT_Disabled, !r);
/* Update edit windows listview */
if (SelectedMain() != shown)
{
TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, ~0);
TR_SetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value, 0);
TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, (ULONG) &EmptyList);
if (SelectedMain())
TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, (ULONG) &SelectedMain()->RefsList);
}
/* Update edit windows information gadgets */
TR_SetAttribute(EditPrj, EDIT_NAME_ID, TRAT_Text, (ULONG) (r ? (STRPTR)r->Name : (STRPTR)""));
TR_SetAttribute(EditPrj, EDIT_OFFSET_ID, TRAT_Value, r ? r->Offset : 0);
TR_SetAttribute(EditPrj, EDIT_LENGTH_ID, TRAT_Value, r ? r->Length : 0);
TR_SetAttribute(EditPrj, EDIT_GOTO_ID, TRAT_Value, r ? r->Goto : 0);
shown = SelectedMain();
} else
shown = (APTR)-1;
}
void
UpdateOptions(void)
{
TR_SetAttribute(OptionsPrj, OPTIONS_AUTODOC_ID, TRAT_Value, Settings.AutoDocPrf.Active);
TR_SetAttribute(OptionsPrj, OPTIONS_C_ID, TRAT_Value, Settings.CPrf.Active);
TR_SetAttribute(OptionsPrj, OPTIONS_C_DEFINE_ID, TRAT_Value, Settings.CPrf.Define);
TR_SetAttribute(OptionsPrj, OPTIONS_C_STRUCT_ID, TRAT_Value, Settings.CPrf.Struct);
TR_SetAttribute(OptionsPrj, OPTIONS_C_TYPEDEF_ID, TRAT_Value, Settings.CPrf.Typedef);
TR_SetAttribute(OptionsPrj, OPTIONS_E_ID, TRAT_Value, Settings.EPrf.Active);
TR_SetAttribute(OptionsPrj, OPTIONS_E_CONST_ID, TRAT_Value, Settings.EPrf.Const);
TR_SetAttribute(OptionsPrj, OPTIONS_E_OBJECT_ID, TRAT_Value, Settings.EPrf.Object);
TR_SetAttribute(OptionsPrj, OPTIONS_E_PROC_ID, TRAT_Value, Settings.EPrf.Proc);
TR_SetAttribute(OptionsPrj, OPTIONS_ASM_ID, TRAT_Value, Settings.AsmPrf.Active);
TR_SetAttribute(OptionsPrj, OPTIONS_ASM_EQU_ID, TRAT_Value, Settings.AsmPrf.Equ);
TR_SetAttribute(OptionsPrj, OPTIONS_ASM_STRUCTURE_ID, TRAT_Value, Settings.AsmPrf.Structure);
TR_SetAttribute(OptionsPrj, OPTIONS_ASM_MACRO_ID, TRAT_Value, Settings.AsmPrf.Macro);
TR_SetAttribute(OptionsPrj, OPTIONS_RECURSIVELY_ID, TRAT_Value, Settings.Recursively);
TR_SetAttribute(OptionsPrj, OPTIONS_KEEPEMPTY_ID, TRAT_Value, Settings.KeepEmpty);
TR_SetAttribute(OptionsPrj, OPTIONS_UNKNOWNFILES_ID, TRAT_Value, Settings.UnknownFiles);
UpdateOptionsGhost();
}
void
UpdateOptionsGhost(void)
{
BOOL ghost;
if (!OptionsPrj)
return;
ghost = !TR_GetAttribute(OptionsPrj, OPTIONS_C_ID, TRAT_Value);
TR_SetAttribute(OptionsPrj, OPTIONS_C_DEFINE_ID, TRAT_Disabled, ghost);
TR_SetAttribute(OptionsPrj, OPTIONS_C_STRUCT_ID, TRAT_Disabled, ghost);
TR_SetAttribute(OptionsPrj, OPTIONS_C_TYPEDEF_ID, TRAT_Disabled, ghost);
ghost = !TR_GetAttribute(OptionsPrj, OPTIONS_E_ID, TRAT_Value);
TR_SetAttribute(OptionsPrj, OPTIONS_E_CONST_ID, TRAT_Disabled, ghost);
TR_SetAttribute(OptionsPrj, OPTIONS_E_OBJECT_ID, TRAT_Disabled, ghost);
TR_SetAttribute(OptionsPrj, OPTIONS_E_PROC_ID, TRAT_Disabled, ghost);
ghost = !TR_GetAttribute(OptionsPrj, OPTIONS_ASM_ID, TRAT_Value);
TR_SetAttribute(OptionsPrj, OPTIONS_ASM_EQU_ID, TRAT_Disabled, ghost);
TR_SetAttribute(OptionsPrj, OPTIONS_ASM_STRUCTURE_ID, TRAT_Disabled, ghost);
TR_SetAttribute(OptionsPrj, OPTIONS_ASM_MACRO_ID, TRAT_Disabled, ghost);
}
void
UpdateSettingsStruct(void)
{
Settings.AutoDocPrf.Active = TR_GetAttribute(OptionsPrj, OPTIONS_AUTODOC_ID, TRAT_Value);
Settings.CPrf.Active = TR_GetAttribute(OptionsPrj, OPTIONS_C_ID, TRAT_Value);
Settings.CPrf.Define = TR_GetAttribute(OptionsPrj, OPTIONS_C_DEFINE_ID, TRAT_Value);
Settings.CPrf.Struct = TR_GetAttribute(OptionsPrj, OPTIONS_C_STRUCT_ID, TRAT_Value);
Settings.CPrf.Typedef = TR_GetAttribute(OptionsPrj, OPTIONS_C_TYPEDEF_ID, TRAT_Value);
Settings.EPrf.Active = TR_GetAttribute(OptionsPrj, OPTIONS_E_ID, TRAT_Value);
Settings.EPrf.Const = TR_GetAttribute(OptionsPrj, OPTIONS_E_CONST_ID, TRAT_Value);
Settings.EPrf.Object = TR_GetAttribute(OptionsPrj, OPTIONS_E_OBJECT_ID, TRAT_Value);
Settings.EPrf.Proc = TR_GetAttribute(OptionsPrj, OPTIONS_E_PROC_ID, TRAT_Value);
Settings.AsmPrf.Active = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_ID, TRAT_Value);
Settings.AsmPrf.Equ = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_EQU_ID, TRAT_Value);
Settings.AsmPrf.Structure = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_STRUCTURE_ID, TRAT_Value);
Settings.AsmPrf.Macro = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_MACRO_ID, TRAT_Value);
Settings.Recursively = TR_GetAttribute(OptionsPrj, OPTIONS_RECURSIVELY_ID, TRAT_Value);
Settings.KeepEmpty = TR_GetAttribute(OptionsPrj, OPTIONS_KEEPEMPTY_ID, TRAT_Value);
Settings.UnknownFiles = TR_GetAttribute(OptionsPrj, OPTIONS_UNKNOWNFILES_ID, TRAT_Value);
}
void
HandleListViewClick(struct TR_Message *m)
{
if (m->trm_Project == MainPrj)
{
UpdateMain();
if (m->trm_Qualifier & IEQUALIFIER_REPEAT)
OpenEditWindow();
}
else if (m->trm_Project == EditPrj)
UpdateEdit();
}
void
HandleMenu(struct TR_Message *m)
{
switch (m->trm_ID)
{
case MAIN_MENU_PROJECT_CLEAR:
LockGUI();
if (rtEZRequestTags("Really clear the entire list?",
"_Okay|_Cancel",
NULL, NULL,
RT_Underscore, '_',
TAG_END))
{
ClearFileList();
TR_SetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value, 0);
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG)&FileList);
UpdateMain();
}
UnlockGUI();
break;
case MAIN_MENU_PROJECT_LOAD:
LockGUI();
if (!IsListEmpty(&FileList))
{
ULONG ret;
ret = rtEZRequestTags( "Current list is not empty!",
"_Replace|_Append|_Cancel",
NULL, NULL,
RT_Underscore, '_',
TAG_END);
if (ret == 0)
{
UnlockGUI();
break;
}
if (ret == 1)
{
ClearFileList();
TR_SetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value, 0);
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG)&FileList);
UpdateMain();
}
}
LoadData(NULL);
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG)&FileList);
UpdateMain();
UnlockGUI();
break;
case MAIN_MENU_PROJECT_SAVE:
LockGUI();
SaveData(NULL);
UnlockGUI();
break;
case MAIN_MENU_PROJECT_OPTIONS:
if (!OptionsPrj)
{
TR_SetAttribute(MainPrj, MAIN_ADD_ID, TRAT_Disabled, TRUE);
if (OptionsPrj = TR_OpenProject(Application, OptionsOutline))
UpdateOptions();
else
TR_SetAttribute(MainPrj, MAIN_ADD_ID, TRAT_Disabled, FALSE);
}
break;
case MAIN_MENU_PROJECT_ABOUT:
LockGUI();
About();
UnlockGUI();
break;
case MAIN_MENU_PROJECT_QUIT:
GoOn = FALSE;
break;
}
}
void
HandleMainIDCMP(struct TR_Message *m)
{
if (m->trm_Class == TRMS_CLOSEWINDOW)
{
GoOn = FALSE;
return;
}
HandleMenu(m);
/* Check for gadgets */
switch (m->trm_ID)
{
case MAIN_ADD_ID:
struct rtFileList *selfiles;
char tmpname[108];
LockGUI();
if (selfiles = rtFileRequest(AddFileReq, tmpname,
"Index files...",
RTFI_Flags, FREQF_MULTISELECT | FREQF_SELECTDIRS,
TAG_END))
{
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, ~0);
IndexFileList(AddFileReq->Dir, selfiles);
rtFreeFileList(selfiles);
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG) &FileList);
UpdateMain();
}
UnlockGUI();
break;
case MAIN_EDIT_ID:
OpenEditWindow();
break;
case MAIN_RESCAN_ID:
struct FileEntry *f;
if (f = SelectedMain())
{
struct Node *new, *last = GetTail(&FileList);
IndexFile("", f->Name);
new = GetTail(&FileList);
/* If rescan added an item to the file list */
if (new != last)
{
struct Node *new;
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, ~0);
/* Attach new list */
new = GetTail(&FileList);
Remove(new);
Insert(&FileList, new, &f->node);
/* Free old list */
while (new = RemHead(&f->RefsList))
FreeVec(new);
Remove(&f->node);
FreeVec(f);
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG) &FileList);
UpdateMain();
break;
} /* else fall through to Delete gadget */
}
case MAIN_DELETE_ID:
struct FileEntry *f;
if (f = SelectedMain())
{
struct Node *n;
ULONG num = TR_GetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value);
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, ~0);
if (num && (num + 1 == NumOfNodes(&FileList)))
TR_SetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value, num - 1);
while (n = RemHead(&f->RefsList))
FreeVec(n);
Remove(&f->node);
FreeVec(f);
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG) &FileList);
UpdateMain();
}
break;
}
}
void
HandleEditIDCMP(struct TR_Message *m)
{
if (m->trm_Class == TRMS_ACTION)
{
if (m->trm_ID == EDIT_OKAY_ID)
{
TR_CloseProject(EditPrj);
EditPrj = NULL;
TR_SetAttribute(MainPrj, MAIN_EDIT_ID, TRAT_Disabled, FALSE);
} else if (m->trm_ID == EDIT_DELETE_ID)
{
struct RefsEntry *r;
if (r = SelectedEdit())
{
ULONG num = TR_GetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value);
TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, ~0);
if (num && (num + 1 == NumOfNodes(&SelectedMain()->RefsList)))
TR_SetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value, num - 1);
Remove(&r->node);
FreeVec(r);
TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, (ULONG) &SelectedMain()->RefsList);
}
}
UpdateMain();
}
}
void
HandleOptionsIDCMP(struct TR_Message *m)
{
static UBYTE prefname[108];
if ((m->trm_Class == TRMS_CLOSEWINDOW) || (m->trm_Class == TRMS_ACTION && m->trm_ID == OPTIONS_CANCEL_ID))
{
TR_CloseProject(OptionsPrj);
OptionsPrj = NULL;
TR_SetAttribute(MainPrj, MAIN_ADD_ID, TRAT_Disabled, FALSE);
}
if (m->trm_Class == TRMS_ACTION)
{
if (m->trm_ID == OPTIONS_USE_ID || m->trm_ID == OPTIONS_SAVE_ID)
{
UpdateSettingsStruct();
if (m->trm_ID == OPTIONS_SAVE_ID)
SaveSettings("ENVARC:FetchRefs_GI.prefs");
SaveSettings("ENV:FetchRefs_GI.prefs");
TR_CloseProject(OptionsPrj);
OptionsPrj = NULL;
TR_SetAttribute(MainPrj, MAIN_ADD_ID, TRAT_Disabled, FALSE);
}
if (m->trm_ID == OPTIONS_MENU_PROJECT_OPEN_ID)
{
if (rtFileRequest(PrefsFileReq, prefname,
"Load settings...",
TAG_END))
{
BPTR newdir, olddir;
if (newdir = Lock(PrefsFileReq->Dir, SHARED_LOCK))
{
struct Prefs tmpsettings;
CopyMem(&Settings, &tmpsettings, sizeof(struct Prefs));
olddir = CurrentDir(newdir);
LoadSettings(prefname);
CurrentDir(olddir);
UnLock(newdir);
UpdateOptions();
CopyMem(&tmpsettings, &Settings, sizeof(struct Prefs));
}
}
}
if (m->trm_ID == OPTIONS_MENU_PROJECT_SAVEAS_ID)
{
if (rtFileRequest(PrefsFileReq, prefname,
"Save settings...",
RTFI_Flags, FREQF_SAVE,
TAG_END))
{
BPTR newdir, olddir;
if (newdir = Lock(PrefsFileReq->Dir, SHARED_LOCK))
{
struct Prefs tmpsettings;
CopyMem(&Settings, &tmpsettings, sizeof(struct Prefs));
UpdateSettingsStruct();
olddir = CurrentDir(newdir);
SaveSettings(prefname);
CurrentDir(olddir);
UnLock(newdir);
CopyMem(&tmpsettings, &Settings, sizeof(struct Prefs));
}
}
}
}
if (m->trm_Class = TRMS_NEWVALUE)
UpdateOptionsGhost();
}
void
HandleGUI(void)
{
struct TR_Message *msg;
while (GoOn)
{
TR_Wait(Application, NULL);
while (msg = TR_GetMsg(Application))
{
if (msg->trm_Class == TRMS_NEWVALUE)
HandleListViewClick(msg);
if (msg->trm_Project == MainPrj)
HandleMainIDCMP(msg);
else if (msg->trm_Project == EditPrj)
HandleEditIDCMP(msg);
else if (msg->trm_Project == OptionsPrj)
HandleOptionsIDCMP(msg);
TR_ReplyMsg(msg);
}
}
}
void
GoGUI(void)
{
NewList(&EmptyList);
if (!ReqToolsBase)
CloseGUI();
if (!TR_OpenTriton(2,
TRCA_Name, "GenerateIndex",
TRCA_LongName, "FetchRefs' GenerateIndex",
TRCA_Info, "Index file generator for FetchRefs",
TRCA_Version, VERSION,
TRCA_Release, VERSION,
TRCA_Date, __COMMODORE_DATE__,
TAG_END))
CloseGUI();
if (!(DataFileReq = rtAllocRequestA(RT_FILEREQ, NULL)))
CloseGUI();
if (!(AddFileReq = rtAllocRequestA(RT_FILEREQ, NULL)))
CloseGUI();
if (!(PrefsFileReq = rtAllocRequestA(RT_FILEREQ, NULL)))
CloseGUI();
if (InitialFile)
{
LoadData(InitialFile);
strcpy(DataName, FilePart(InitialFile));
if (PathPart(InitialFile) != InitialFile)
{
*(PathPart(InitialFile)) = 0;
rtChangeReqAttr(DataFileReq, RTFI_Dir, InitialFile, TAG_END);
}
}
if (!(MainPrj = TR_OpenProject(Application, MainOutline)))
CloseGUI();
TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG)&FileList);
UpdateMain();
HandleGUI();
CloseGUI();
}
void
CloseGUI(void)
{
if (ReqToolsBase)
{
rtFreeRequest(DataFileReq);
rtFreeRequest(AddFileReq);
rtFreeRequest(PrefsFileReq);
} else
CloseAll(ERROR_SPECIAL, "You need ReqTools version 38+ for the GUI!");
if (TritonBase)
{
if (OptionsPrj)
TR_CloseProject(OptionsPrj);
if (EditPrj)
TR_CloseProject(EditPrj);
if (MainPrj)
TR_CloseProject(MainPrj);
TR_CloseTriton();
} else
CloseAll(ERROR_SPECIAL, "You need Triton version 2+ for the GUI!");
}